package club.cearnach.entity;

import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;

/**
 * 电影信息
 *
 * @author 阮胜
 * @date 2018/5/4 17:06
 */
@Data
@Entity
@DynamicUpdate
@DynamicInsert
public class Movie implements Serializable {
    private static final long serialVersionUID = -8154160345912410818L;

    @Id
    @Column(name = "movie_id")
    @GeneratedValue
    private Integer id;
    /**
     * 电影名
     */
    @NotBlank
    @Column(name = "movie_name")
    private String name;
    /**
     * 评分
     */
    @Column(name = "movie_rate")
    private Float rate;
    /**
     * 导演
     */
    @ManyToMany(cascade = {CascadeType.REFRESH, CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST})
    private Set<Director> directors;

    /**
     * 主演
     */
    @ManyToMany(cascade = {CascadeType.REFRESH, CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST})
    private Set<Actor> actors;
    /**
     * 类型
     */
    @ManyToOne
    @JoinColumn(name = "movie_type_id")
    private MovieType type;
    /**
     * 上映日期
     */
    @Column(name = "movie_initial_release_date")
    private String initialReleaseDate;
    /**
     * 语言
     */
    @ManyToOne
    @JoinColumn(name = "movie_language_id")
    private MovieLanguage movieLanguage;
    /**
     * 地区
     */
    @Column(name = "movie_location")
    private String location;
    /**
     * 片长
     */
    @Column(name = "movie_length")
    private String duration;
    /**
     * 简介
     */
    @Column(name = "movie_description", length = 1024)
    private String description;
    /**
     * 电影缩略图
     */
    @Column(name = "movie_image_file_name")
    private String imageFileName;

    @Column(name = "movie_video_file_name")
    private String videoFileName;

    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
    private Date updateDate;
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", updatable = false)
    private Date createDate;

    public Movie() {
    }

    public Movie(String name, float rate, Set<Director> directors, Set<Actor> actors, MovieType type, String initialReleaseDate
            ,MovieLanguage movieLanguage, String location, String duration, String description, String imageFileName) {
        this.name = name;
        this.rate = rate;
        this.directors = directors;
        this.actors = actors;
        this.type = type;
        this.initialReleaseDate = initialReleaseDate;
        this.movieLanguage = movieLanguage;
        this.location = location;
        this.duration = duration;
        this.description = description;
        this.imageFileName = imageFileName;

    }
}
